package org.box.metadata.shell;

import org.box.metadata.cli.MetaCommandLineParser;
import org.box.metadata.cli.MetaCommandLineParser.ParserType;
import org.box.metadata.cli.exception.ParseException;

/**
 * Designed for internal purposes and holds an application's instance and
 * related for this instance stuff
 * 
 * @see CommandHandler
 * 
 * @author <a href="mailto:alexander.box@gmail.com">Alexander Korobka</a>
 * 
 * @param <Object>
 *            - a type of the application's configuration
 */
public class ConfigurationHolder {

	private final Class<?> cfgClass;
	private final MetaCommandLineParser<Object> parser;

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public ConfigurationHolder(Class<?> cfgClass, ParserType parserType) {
		this.cfgClass = cfgClass;
		parser = new MetaCommandLineParser(cfgClass, parserType);
		parser.setIncCommonOptions(false);
	}


	/**
	 * Parsers the Command Line and return an instance of the application's
	 * configuration
	 * 
	 * @param args
	 *            - the Command Line
	 * 
	 * @return an instance of the application's configuration
	 * 
	 * @throws ParseException if the Command Line is incorrect.
	 */
	public Object parse(String[] args) throws ParseException {
		return parser.parse(args);
	}


	public Class<?> getCfgClass() {
		return cfgClass;
	}
}
